package com.majie.aop.aspect;

import com.majie.aop.notspring.Person;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory;

@Aspect
class MyAspect {

	@Pointcut("execution(* run(..))")
	private void beforeAdd( ) {
	}

	@Before("beforeAdd()")
	public void before1( ) {
		System.out.println("-----------before-----------");
	}

	public static void main(String[] args) {
		AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new Person());
		// 注意：此处得MyAspect类上面的@Aspect注解必不可少
		proxyFactory.addAspect(MyAspect.class);
		//proxyFactory.setProxyTargetClass(true);//是否需要使用CGLIB代理
		Person proxy = proxyFactory.getProxy();
		proxy.run();

		System.out.println(proxy.getClass());
	}
}